﻿#region File Description
//-----------------------------------------------------------------------------
// TapTask
//
// Copyright © 2013 Wave Coorporation. All rights reserved.
// Use is subject to license terms.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using WaveEngine.Extensions.ITasks;
using System;
using System.Collections.Generic;
using WaveEngine.Components.Gestures;
using WaveEngine.Framework;
#endregion

namespace WaveEngine.Extensions.ITasks.PrimiviteTasks
{
    public class TapTask : TaskBase
    {
        /// <summary>
        /// Gets or sets the touch gestures.
        /// </summary>
        /// <value>
        /// The touch gestures.
        /// </value>
        public TouchGestures TouchGestures { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="TapTask" /> class.
        /// </summary>
        /// <param name="scene">The scene.</param>
        /// <param name="taskName">Name of the task.</param>
        /// <param name="touchGestures">The touch gestures.</param>
        public TapTask(Scene scene, string taskName, TouchGestures touchGestures)
            : base(scene, taskName)
        {
            this.TouchGestures = touchGestures;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TapTask" /> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="taskName">Name of the task.</param>
        /// <param name="touchGestures">The touch gestures.</param>
        public TapTask(ITask parent, string taskName, TouchGestures touchGestures)
            : base(parent, taskName)
        {
            this.TouchGestures = touchGestures;
        }

        /// <summary>
        /// Ons the run.
        /// </summary>
        protected override void performRun()
        {
            this.TouchGestures.TouchTap+=notifyTap;
        }

        /// <summary>
        /// Handles the Completed event of the singleAnimation control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        void notifyTap(object sender, EventArgs e)
        {
            this.performCompleted();
            this.TouchGestures.TouchTap -= notifyTap;
        }

        /// <summary>
        /// Notifies the cancelled.
        /// </summary>
        protected override void performCancel()
        {
            this.TouchGestures.TouchTap -= notifyTap;
            base.performCancel();
        }

        /// <summary>
        /// Notifies the skip.
        /// </summary>
        /// <returns></returns>
        protected override bool performSkip()
        {
            if (this.IsSkippable)
            {
                this.Cancel();
                return base.performSkip();
            }
            else
                return false;
        }

    }
}
